<div class="page" id="ranks">
	<?php if($this->view->func == 'index') { ?>
		<h3><a href="console" data-to="ajax">Console</a> / Ranks</h3>
		<span class="advice">Create or update existing ranks plus move users between them by simply dragging and dropping.</span>
		<table>
			<tr>
				<td>
					<form class="ranks_handlers">
						<div class="left"><button data-handle="new">New Rank</button></div>
						<div class="clear"></div>
					</form>
				</td>
			</tr>
			<tr><td class="delimiter"></td></tr>
			<?php if(count($this->view->data) > 0) { ?>
				<?php foreach($this->view->data as $one) { ?>
					<tr>
						<td class="cat">
							<div class="drop" data-id="<?php echo $one['id']; ?>">
								<h4 class="left"><a href="ranks/edit/<?php echo $one['link']; ?>" data-to="ajax"><?php echo $one['name']; ?></a></h4>
								<div class="actions">
									<span class="bull">•</span>#<?php echo $one['id']; ?>
									<span class="bull">•</span>
									<?php if($one['id'] == $this->settings['rank_apply']) { ?>
										Default
									<?php } else { ?>
										<a href="javascript:void(0);" class="rank_delete" data-id="<?php echo $one['id']; ?>">Delete</a>
									<?php } ?>
								</div>
								<div class="drag">
									<?php foreach($one['listing'] as $member) { ?>
										<a data-id="<?php echo $member['id']; ?>" data-origin="<?php echo $one['id']; ?>" href="profile/view/<?php echo $member['link']; ?>" data-to="ajax"><?php echo $member['name']; ?></a>
									<?php } ?>
									<div class="clear"></div>
								</div>
							</div>
						</td>
					</tr>
					<tr><td class="delimiter"></td></tr>
				<?php } ?>
			<?php } else { ?>
				<tr><td>No ranks defined.</td></tr>
			<?php } ?>
			<tr>
				<td>
					<form class="ranks_handlers">
						<div class="left"><button data-handle="new">New Rank</button></div>
						<div class="clear"></div>
					</form>
				</td>
			</tr>
		</table>
	<?php } else { ?>
		<h3><a href="console" data-to="ajax">Console</a> / <a href="ranks" data-to="ajax">Ranks</a> / <?php echo $this->view->rank['name']; ?></h3>
		<span class="advice">Here you can modify the rank name, if it has root access or not and the forum permissions.</span>
		<form id="form_ranks">
			<input type="hidden" name="token" value="<?php echo $this->view->rank['id']; ?>" />
			<div class="left half">
				<label class="input">
					<input type="text" value="<?php echo $this->view->rank['id'] != 0 ? $this->view->rank['name'] : ''; ?>" name="name" maxlength="70">
					<span>Name</span>
				</label>
			</div>
			<div class="right half">
				<label class="select">
					<select name="root">
						<option value="0">Root Access: No</option>
						<option value="1"<?php echo isset($this->view->rank['permissions']['root']) ? ' selected="selected"' : ''; ?>>Root Access: Yes</option>
					</select>
				</label>
			</div>
			<div class="clear"></div>
			<br />
			<table>
				<tr>
					<td><h4>Forum Permissions</h4></td>
					<td class="chk">View Category</td>
					<td class="chk">Create Topics</td>
					<td class="chk">Moderate Posts</td>
				</tr>
				<tr><td colspan="4" class="delimiter header"></td></tr>
				<?php if(count($this->view->cats) > 0) { ?>
					<?php foreach($this->view->cats as $one) { ?>
						<tr>
							<td><a href="/forum/category/<?php echo $one['link']; ?>" data-to="ajax"><?php echo $one['name']; ?></a></td>
							<td class="chk"><input name="forum[view][<?php echo $one['id']; ?>]" value="<?php echo $one['id']; ?>" type="checkbox"<?php echo isset($this->view->rank['permissions']['forum']['view'][$one['id']]) && $one['type'] == 0 ? 'checked="checked"' : ''; echo $one['type'] != 0 ? 'disabled="disabled" checked="checked"' : ''; ?> /></td>
							<td class="chk"><input name="forum[create][<?php echo $one['id']; ?>]" value="<?php echo $one['id']; ?>" type="checkbox"<?php echo isset($this->view->rank['permissions']['forum']['create'][$one['id']]) ? 'checked="checked"' : ''; ?> /></td>
							<td class="chk"><input name="forum[moderate][<?php echo $one['id']; ?>]" value="<?php echo $one['id']; ?>" type="checkbox"<?php echo isset($this->view->rank['permissions']['forum']['moderate'][$one['id']]) ? 'checked="checked"' : ''; ?> /></td>
						</tr>
						<tr><td colspan="4" class="delimiter"></td></tr>
					<?php } ?>
				<?php } else { ?>
					<tr><td colspan="4">No categories defined.</td></tr>
				<?php } ?>
			</table>
			<div class="right"><button type="submit">Save</button></div>
			<div class="clear"></div>
		</form>
	<?php } ?>
</div>